<?php
require_once 'common.inc.php';

if ($operation == 'display'){

    $condition = " bm.uniacid = $uniacid and bm.uid > 0 and m.nickname != '' ";
    
    if(!empty($_GPC['keyword'])){
        $condition .= " and m.nickname like '%".$_GPC['keyword']."%' or m.realname like '%".$_GPC['keyword']."%' or m.mobile like '%".$_GPC['mobile']."%' ";
    }
    
    $totalall = pdo_fetchcolumn("select count(1) from ".tablename(MODULE_PREFIX."member")." bm left join ".tablename("mc_members")." m on bm.uid = m.uid where bm.uid > 0 and bm.uniacid = $uniacid  ");
    
    $list  = pdo_fetchall("select bm.*,m.nickname m_nickname,m.realname,m.mobile,m.avatar,m.credit1,m.credit2 from ".tablename(MODULE_PREFIX."member")." bm left join ".tablename("mc_members")." m on bm.uid = m.uid where $condition order by m.credit1 desc,m.credit2 desc ");
    foreach ($list as &$item){
        $item['posternum'] = pdo_fetchcolumn("select count(1) from ".tablename(MODULE_PREFIX."qr")." where uid = ".intval($item['uid']));
    }
    $total = pdo_fetchcolumn("select count(*) from ".tablename(MODULE_PREFIX."member")." bm left join ".tablename("mc_members")." m on bm.uid = m.uid where $condition ");
    $pager = pagination($total, $pindex, $psize);
}

elseif($operation == 'statistics'){
    $max_level = pdo_fetchcolumn("select max(level_num) from ".tablename(MODULE_PREFIX."member")." where uniacid =:uniacid ",array(':uniacid'=>$uniacid)); 

    $list = array();
    for($i = 0;$i <= $max_level;$i ++){
        $list[$i] = array(
            'name' => $i.'级人数：'.pdo_fetchcolumn("select count(1) from ".tablename(MODULE_PREFIX."member")." where uniacid=:uniacid and level_num =:level_num ",array(':uniacid'=>$uniacid,':level_num'=>$i)),
        );
    }
}

elseif($operation == 'addAll_ceshi'){

    for ($i=0; $i < 100; $i++) {
        $in_data = array(
            'uniacid' => $uniacid,
            'openid' => random(32),
            'uid' => 0,
            'createtime' => time(),
            'level_num' => $i,
            'isceshi' => 1,
        );
        pdo_insert(MODULE_PREFIX."member",$in_data);        
    }

    message("添加成功",$this->createWebUrl('member',array('op'=>'display')),"success");
}

elseif($operation == 'deleteAll_ceshi'){
    pdo_delete(MODULE_PREFIX."member",array('isceshi'=>1));
    message("清空成功",referer(),"success");
}

include $this->template('web/member');